"""
日记相关的API数据模型
"""
from typing import Optional, List
from datetime import datetime
from pydantic import BaseModel, Field


class DiaryBase(BaseModel):
    """日记基础模型"""
    title: str = Field(..., max_length=200, description="日记标题")
    content: str = Field(..., description="日记内容(markdown)")
    tags: Optional[List[str]] = Field(default_factory=list, description="标签列表")
    mood: Optional[float] = Field(None, ge=-1, le=1, description="情绪评分(-1到1)")


class DiaryCreate(DiaryBase):
    """创建日记模型"""
    pass


class DiaryUpdate(BaseModel):
    """更新日记模型"""
    title: Optional[str] = Field(None, max_length=200, description="日记标题")
    content: Optional[str] = Field(None, description="日记内容(markdown)")
    tags: Optional[List[str]] = Field(None, description="标签列表")
    mood: Optional[float] = Field(None, ge=-1, le=1, description="情绪评分(-1到1)")


class Diary(DiaryBase):
    """日记返回模型"""
    id: int
    user_id: int
    word_count: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class DiaryList(BaseModel):
    """日记列表模型"""
    id: int
    title: str
    word_count: int
    mood: Optional[float]
    tags: List[str]
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class DiarySearch(BaseModel):
    """日记搜索参数"""
    keyword: Optional[str] = Field(None, description="关键词")
    tags: Optional[List[str]] = Field(None, description="标签筛选")
    mood_min: Optional[float] = Field(None, ge=-1, le=1, description="最小情绪值")
    mood_max: Optional[float] = Field(None, ge=-1, le=1, description="最大情绪值")
    date_from: Optional[datetime] = Field(None, description="开始日期")
    date_to: Optional[datetime] = Field(None, description="结束日期")
    page: int = Field(1, ge=1, description="页码")
    page_size: int = Field(20, ge=1, le=100, description="每页数量") 